// 加载地图script
const MAP_API_URL = {
  AMap: 'https://webapi.amap.com/maps?v=2.0&callback=initializeMap&key=db4b48fb15aecc4e23ffd395910dd5a6&plugin=AMap.AutoComplete,AMap.PlaceSearch,AMap.PolygonEditor,AMap.DistrictLayer,AMap.DistrictSearch,AMap.ToolBar,AMap.MarkerCluster,AMap.Geocoder',
  BMap: 'https://api.map.baidu.com/api?v=3.0&ak=8oPCO3idn3bM0yMj7RAe9ujwrSSyL1uz&callback=initializeMap',
}
function getScriptSrc() {
  return MAP_API_URL['AMap']
}

export function loadMapScript() {
  return new Promise((resolve, reject) => {
    const globalMap = window.AMap || window.BMap
    if (globalMap) {
      resolve(globalMap)
    } else {
      var script = document.createElement('script')
      script.type = 'text/javascript'
      script.async = true
      script.src = getScriptSrc()
      script.onerror = reject
      document.head.appendChild(script)
    }
    window.initializeMap = () => {
      resolve(globalMap)
    }
  })
}
